import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:local_coffee/request/routers.dart';

class RqtShop {
  
  final Dio _dio;

  RqtShop(
    this._dio
  );

  /// 商品列表
  /// ```
  /// @params {String} orderBy 排序规则
  /// @param {int} page 获取第几页数据
  /// @param {int} pageSize 每页显示多少数据
  /// @param {int} status 状态: -1: 全部状态; 0: 上架; 1: 下架;
  /// ```
  Future<Response> goodsList({
    String orderBy = 'ordersDown',
    int page,
    int pageSize,
    int status = 0
  }) {
    return _dio.post(
      Routers.shopGoodsList,
      queryParameters: {
        'orderBy': orderBy,
        'page': page,
        'pageSize': pageSize,
        'status': status
      }
    );
  }

  /// 商品类别
  Future<Response> goodsCategoryAll() {
    return _dio.post(Routers.shopGoodsCategoryAll);
  }

  /// 商品详情
  /// ```
  /// @param {int} id 商品id
  /// ```
  Future<Response> goodsDetail({
    @required int id
  }) {
    return _dio.post(
      Routers.shopGoodsDetail,
      queryParameters: {
        'id': id
      }
    );
  }

  /// 获取商品价格
  /// ```
  /// @param {int} id 商品id
  /// @param {String} propertyChildIds 选择的规格尺寸信息：如：4:15, 2:10, 1:4. 多个规格请用英文的逗号分割，4:15 中的 4 获取代表颜色，15 或许代表 土豪金
  /// ```
  Future<Response> goodsPrice({
    @required int goodsId,
    @required String propertyChildIds
  }) {
    return _dio.post(
      Routers.shopGoodsPrice,
      queryParameters: {
        'goodsId': goodsId,
        'propertyChildIds': propertyChildIds
      }
    );
  }
}